<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<!-- http://localhost:8080/crowdfunding02-admin-webui/index.jsp -->
<base
	href="http://${pageContext.request.serverName }:${pageContext.request.serverPort }${pageContext.request.contextPath}/" />
</head>
<script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>
<script type="text/javascript">
	
	$(function(){

		$("#btn5").click(function () {

			layer.msg("layer弹框");

		});




		$("#btn4").click(function(){
			
			//准备好发送给服务器的数据
			var student = {
					"stuId":1,
					"stuName":"张三",
					"address":{
						"city":"宜昌市",
						"area":"西陵区"
					},
					"subjectList":[
						{
							"subjectName":"语文",
							"sujectScope": 100
						},
						{
							"subjectName":"数学",
							"sujectScope":90
						}
					],
					"map":{
						"k1":"v1",
						"k2":"v2"
					}
			};
			
			//将JSON对象转换为JSON字符串
			var requsetBody = JSON.stringify(student);
			
			$.ajax({
				"url":"send/array/compse.json",
				"type":"post",
				"data":requsetBody,
				"dataType":"json",
				"contentType":"application/json;charset=UTF-8",
				"success":function(response){
					console.log(response);
				},"error":function(response){
					console.log(response);
				}
			});
		});

		
		//推荐使用的方式
		$("#btn3").click(function(){
			
			//准备好要发送给服务器的数组
			var array = [5,8,9];
			console.log(array.length);
			
			//将JSON数组转换为JSON字符串
			var requestBody = JSON.stringify(array);
			console.log(requestBody.length);
			
			$.ajax({
				"url":"send/three/array.html",            //请求目标资源的地址
				"type":"post",						//请求类型
				"data":requestBody,					//请求的参数
				"contentType":"application/json;charset=UTF-8",  //设置请求体的内容类型
				"dataType":"text",					//如何解析服务器端返回的数据
				"success":function(response){		//服务器处理成功后调用的回调函数
					alert(response);
				},
				"error":function(response){			//服务器处理失败后调用的回调函数
					alert(response);
				}
			});
		});
		
		
		
		$("#btn2").click(function(){
			$.ajax({
				"url":"send/two/array.html",            //请求目标资源的地址
				"type":"get",						//请求类型
				"data":{							//请求的参数
					"array[0]":1,
					"array[1]":2,
					"array[2]":3
				},
				"dataType":"text",					//如何解析服务器端返回的数据
				"success":function(response){		//服务器处理成功后调用的回调函数
					alert(response);
				},
				"error":function(response){			//服务器处理失败后调用的回调函数
					alert(response);
				}
			});
		});
		
		
		
		
		$("#btn1").click(function(){
			$.ajax({
				"url":"send/one/array.html",            //请求目标资源的地址
				"type":"get",						//请求类型
				"data":{							//请求的参数
					"array":[1,2,3]
				},
				"dataType":"text",					//如何解析服务器端返回的数据
				"success":function(response){		//服务器处理成功后调用的回调函数
					alert(response);
				},
				"error":function(response){			//服务器处理失败后调用的回调函数
					alert(response);
				}
			});
		});

	});
	
</script>
<body>
	<a href="test-ssm.html">SSM测试</a>

	<br />

	<button id="btn1">send [1,2,3] One</button>

	<br />

	<button id="btn2">send [1,2,3] Two</button>
	<br />

	<button id="btn3">send [1,2,3] Three</button>
	<br />

	<button id="btn4">send Compose Object</button>
	<br/>

	<button id="btn5">点我弹框</button>


</body>
</html>